package com.wn.inventory.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wn.common.ActivitiStartEntity;
import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.BorrowWarehouseApplication;
import com.wn.entity.Hr;
import com.wn.inventory.feign.ActivitiFeignClient;
import com.wn.inventory.mapper.BorrowWarehouseApplicationMapper;
import com.wn.inventory.service.BorrowWarehouseApplicationService;
import com.wn.inventory.vo.BorrowWarehouseApplicationVo;
import com.wn.utils.CurrentTime;
import com.wn.utils.PageBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.concurrent.BrokenBarrierException;

/**
 * @ author     ：NST
 * @ date       ：Created in 2022/10/22 14:08
 * @ description：
 * @ modified By：
 * @ version:
 */
@Service
public class BorrowWarehouseApplicationImpl implements BorrowWarehouseApplicationService {
    @Autowired
    BorrowWarehouseApplicationMapper borrowWarehouseApplicationMapper;
    @Autowired
    ActivitiFeignClient activitiFeignClient;
    /**
     * @param borrowWarehouseApplication
     * @return void
     * @ author nst
     * @ date 2022/10/22 14:09
     * @ Description 增加借用出库信息
     */
    @Override
    public void insert(BorrowWarehouseApplication borrowWarehouseApplication, HttpServletRequest request) {
        borrowWarehouseApplication.setApplicant(new Hr(Integer.parseInt(request.getHeader("userId"))));
        borrowWarehouseApplication.setApplyTime(CurrentTime.getCurrentTime());
        String identifier="BWA"+ CurrentTime.getCurrentTimeString();
        borrowWarehouseApplication.setIdentifier(identifier);
        ResponseEntity<String> entity = activitiFeignClient.startInstance(new ActivitiStartEntity("in_warehouss_application_id", "user1", request.getHeader("userWorkNumber")));
//        activitiFeignClient.completeTask(new ActivitiCompleteEntity("in_warehouss_application_id",entity.getData(),"user1",));
        borrowWarehouseApplication.setActivitiInstanceId(entity.getData());
        borrowWarehouseApplicationMapper.insert(borrowWarehouseApplication);
    }
    /**
     * @param borrowWarehouseApplicationVo
     * @return java.util.List<com.wn.entity.BorrowWarehouseApplication>
     * @ author nst
     * @ date 2022/10/22 14:09
     * @ Description 多条件分页查询借用出库信息
     */
    @Override
    public PageBean<BorrowWarehouseApplication> getByCondition(BorrowWarehouseApplicationVo borrowWarehouseApplicationVo) {
        Page<BorrowWarehouseApplication> page = PageHelper.startPage(borrowWarehouseApplicationVo.getCurrPage(), borrowWarehouseApplicationVo.getPageSize());
        List<BorrowWarehouseApplication> list = borrowWarehouseApplicationMapper.getByCondition(borrowWarehouseApplicationVo.getBorrowWarehouseApplication());
        return PageBeanUtil.getPageBean(list,page,borrowWarehouseApplicationVo.getCurrPage(),borrowWarehouseApplicationVo.getPageSize());
    }
}
